package b4
{
	import b4.controller.*;
	import b4.model.*;
	import b4.view.*;
	import b4.view.component.*;
	
	import org.puremvc.as3.interfaces.IFacade;
	import org.puremvc.as3.patterns.facade.Facade;
	import org.puremvc.as3.patterns.observer.Notification;

	public class ApplicationFacade extends Facade implements IFacade
	{
		public static const NAME:String					= 'ApplicationFacade';
		
		public static const PACKAGE_LOADED:String		= NAME + "PackageLoaded";
		public static const RESOURCE_LOADED:String		= NAME + 'ResourceLoaded';
		public static const RESOURCE_PROGRESS:String	= NAME + 'ResourceProgress';
		public static const STARTUP:String				= NAME + 'StartUp';
		public static const MAINROLE_LOADED:String		= NAME + 'MainRoleLoaded';
		public static const ENTER_TOWN:String			= NAME + 'EnterTown';
		public static const LOAD_TOWN_RESOURCE:String	= NAME + 'LoadTownResource';
		public static const TRANSPORT_MAINROLE:String	= NAME + 'TransportMainRole';
		
		public static function getInstance():ApplicationFacade
		{
			return (instance ? instance : new ApplicationFacade()) as ApplicationFacade;
		}
		
		override protected function initializeController():void
		{
			super.initializeController();
			
			registerCommand(STARTUP, StartupCommand);
			registerCommand(MainFuncBarMediator.SHOW_PACKAGE, ShowPackageCommand);
			registerCommand(MainFuncBarMediator.SHOW_SMITHY, ShowSmithyCommand);
			registerCommand(ENTER_TOWN, EnterTownCommand);
			registerCommand(LOAD_TOWN_RESOURCE, LoadTownResourceCommand);
			registerCommand(RESOURCE_LOADED, ResourceLoadedCommand);
			registerCommand(TRANSPORT_MAINROLE, TransportMainRoleCommand);
			registerCommand(MainFuncBarMediator.SHOW_HUMAN_BEING, ShowHumanBeingCommand);
		}
		
		public function startup(stage:Object):void
		{
			sendNotification(STARTUP, stage);
		}
		
		override public function sendNotification(notificationName:String, body:Object=null, type:String=null):void
		{
			notifyObservers(new Notification(notificationName, body, type));
		}
	}
}